package com.lottery.im.base;

import android.app.Activity;
import com.kaopiz.kprogresshud.KProgressHUD;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.FragmentEvent;

/**
 * 基础presenter
 * Created by xybcoder on 2016/3/1.
 */
public abstract class BaseFragmentPresenter<T extends BaseView> {

  protected LifecycleProvider<FragmentEvent> provider;
  protected Activity activity;
  protected T iView;

  private KProgressHUD mProgressHUD;

  public BaseFragmentPresenter(Activity activity, T iView,
      LifecycleProvider<FragmentEvent> provider) {
    this.activity = activity;
    this.iView = iView;
    this.provider = provider;
  }

  //显示加载框
  public void showLoadingProgress(final String label) {
    activity.runOnUiThread(() -> mProgressHUD = KProgressHUD.create(activity)
        .setStyle(KProgressHUD.Style.SPIN_INDETERMINATE)
        .setLabel(label)
        //.setCancellable(false)//点击返架取消
        .setGraceTime(500)
        .setSize(110, 110)
        .show());
  }

  //关闭加载框
  public void closeLoadingProgress() {
    activity.runOnUiThread(() -> {
      if (mProgressHUD != null) {
        mProgressHUD.dismiss();
      }
    });
  }

  public void init() {
    iView.initView();
  }

  public void onDestroy() {
    iView = null;
  }
}
